/**
 * 
 */
package fr.isima.isipaint.gui;

import java.awt.Color;
import java.awt.Point;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JPanel;

import fr.isima.isipaint.controllers.DrawPanelObjectController;
import fr.isima.isipaint.model.Scene;

/**
 * @author daniel
 * 
 */
public final class DrawPanel extends JPanel implements Observer {

	/**
	 * Generated serial
	 */
	private static final long serialVersionUID = 1L;

	/** The model, is the "root" group */
	private Scene scene;

	/** The mousse listenner */
	DrawPanelObjectController listenner;

	/**
	 * @param scene
	 */
	public DrawPanel(Scene scene, DrawPanelObjectController listenner) {
		setBackground(Color.WHITE);
		setLayout(null);
		setLocation(new Point(0, 0));
		this.scene = scene;
		add(scene.getGroup());
		add(scene.getSelectionBox());
		scene.addObserver(this);
		this.listenner = listenner;
		addMouseListener(listenner);
		addMouseMotionListener(listenner);
		setVisible(true);		
	}

	@Override
	public void update(Observable o, Object arg) {

		repaint();
		if(scene.getCurrent() != null)
		{
			scene.getCurrent().repaint();
		}
		if(scene.isSelection())
		{
			scene.getSelectionBox().repaint();
		}
		
	}
	

}
